package com.payment.system.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.payment.common.base.AjaxResult;
import com.payment.common.support.Convert;
import com.payment.common.utils.StringUtils;
import com.payment.system.domain.ShoppingProduct;
import com.payment.system.mapper.ShoppingProductMapper;
import com.payment.system.service.IShoppingProductService;

/**
 * 商品 服务层实现
 *
 * @author payment
 * @date 2019-08-21
 */
@Service
public class ShoppingProductServiceImpl implements IShoppingProductService {
    @Autowired
    private ShoppingProductMapper shoppingProductMapper;

    /**
     * 查询商品信息
     *
     * @param id 商品ID
     * @return 商品信息
     */
    @Override
    public ShoppingProduct selectShoppingProductById(String id) {
        return shoppingProductMapper.selectShoppingProductById(id);
    }

    /**
     * 查询商品列表
     *
     * @param shoppingProduct 商品信息
     * @return 商品集合
     */
    @Override
    public List<ShoppingProduct> selectShoppingProductList(ShoppingProduct shoppingProduct) {
        return shoppingProductMapper.selectShoppingProductList(shoppingProduct);
    }

    /**
     * 新增商品
     *
     * @param shoppingProduct 商品信息
     * @return 结果
     */
    @Override
    public int insertShoppingProduct(ShoppingProduct shoppingProduct) {
        return shoppingProductMapper.insertShoppingProduct(shoppingProduct);
    }

    /**
     * 修改商品
     *
     * @param shoppingProduct 商品信息
     * @return 结果
     */
    @Override
    public int updateShoppingProduct(ShoppingProduct shoppingProduct) {
        return shoppingProductMapper.updateShoppingProduct(shoppingProduct);
    }

    /**
     * 删除商品对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteShoppingProductByIds(String ids) {
        return shoppingProductMapper.deleteShoppingProductByIds(Convert.toStrArray(ids));
    }

    /**
     * 获取商品列表
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public AjaxResult selectShoppingProductListByApp(Integer pageNum, Integer pageSize) {
        if (pageSize == null || pageNum == null) {
            return AjaxResult.error(1, "缺失必要参数");
        }
        List<ShoppingProduct> list = shoppingProductMapper.selectShoppingProductListByApp(pageNum * pageSize, pageSize);
        return AjaxResult.successAndData("获取商品信息成功", list);
    }


    /**
     * 获取商品列表
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public AjaxResult selectShoppingProductListByAppSH(Integer pageNum, Integer pageSize) {
        if (pageSize == null || pageNum == null) {
            return AjaxResult.error(1, "缺失必要参数");
        }
        List<ShoppingProduct> list = shoppingProductMapper.selectShoppingProductListByAppSH(pageNum * pageSize, pageSize);
        return AjaxResult.successAndData("获取商品信息成功",list);
    }

    /**
     * app -商品详情
     *
     * @param productId
     * @return
     */
    @Override
    public AjaxResult selectProductDetails(String productId) {
        if (StringUtils.isEmpty(productId)) {
            return AjaxResult.error(1, "缺失必要参数");
        }
        ShoppingProduct product = shoppingProductMapper.selectShoppingProductById(productId);
        if (product == null) {
            return AjaxResult.error(2, "该商品信息不存在");
        }
        return AjaxResult.successAndData("获取商品详情成功", product);
    }

}
